package com.yangyang.androidconnect.service;

import com.alibaba.fastjson.JSONObject;
import com.yangyang.androidconnect.MyApplication;
import com.yangyang.androidconnect.common.ApiResult;
import com.yangyang.androidconnect.vo.response.FileInfo;

import java.util.List;

public class FileService {

    public static ApiResult getDBList(String path, Integer page, Integer pageSize, boolean showHidden) {
        FileIndexService fileIndexService = MyApplication.getInstance().getFileIndexService();
        // 使用数据库查询
        FileIndexService.FileListResult result = fileIndexService.getFileList(path, page, pageSize, "last_modified", false);

        // 过滤隐藏文件（如果需要）
        List<FileInfo> filteredList = result.files;
        if (!showHidden) {
            filteredList.removeIf(file -> file.getName().startsWith("."));
        }

        // 构建响应
        JSONObject json = new JSONObject();
        json.put("list", filteredList);
        json.put("path", path);
        json.put("total", result.total);
        json.put("page", page);
        json.put("pageSize", pageSize);

        return ApiResult.ok(json);
    }
}
